//
//  I_CoachSchedule.m
//  YunDongGym
//
//  Created by lqq on 2018/7/18.
//  Copyright © 2018年 lqq. All rights reserved.
//

#import "I_Schedule.h"
#import "NSDate+Extension.h"

@implementation I_Schedule

/**
 查询教练一天的日程
 */
+ (NetworkTask *)requestCoachScheduleInOneDayWithDate:(NSDate *)date
                                              success:(void(^)(NSMutableArray *list))successBlock
                                               failue:(ErrorBlock)failureBlock
{
    NSString *scheduleDate = [Toolkit stringFromDate:date formatterString:@"yyyy-MM-dd"];
    NSDictionary *params = @{@"startDate":scheduleDate};
    return [NET POST:@"/gym-api/admin/1.0.0/listScheduleStat" parameters:params criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        NSMutableArray *list = [M_Schedule arrayOfModelsFromDictionaries:SAFE_VALUE_FOR_KEY(resultObject, @"data") error:nil];
        if (successBlock) {
            successBlock(list);
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}

/**
 查询教练一周的日程
 */
+ (NetworkTask *)requestCoachScheduleInOneWeekWithDate:(NSDate *)date
                                               success:(void(^)(NSMutableArray *list))successBlock
                                                failue:(ErrorBlock)failureBlock
{
    NSArray *dateList = [date getFirstAndLastDayOfThisWeek];
    NSString *scheduleDate = [Toolkit stringFromDate:dateList.firstObject formatterString:@"yyyy-MM-dd"];
    NSString *scheduleEndDate = [Toolkit stringFromDate:dateList.lastObject formatterString:@"yyyy-MM-dd"];

    NSDictionary *params = @{@"startDate":scheduleDate,
                             @"endDate":scheduleEndDate
                             };
    return [NET POST:@"/gym-api/admin/1.0.0/listScheduleStatWeek" parameters:params criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        NSMutableArray *list = [M_ScheduleWeek arrayOfModelsFromDictionaries:SAFE_VALUE_FOR_KEY(resultObject, @"data") error:nil];
        if (successBlock) {
            successBlock(list);
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}
@end
